#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
登入授权相关表单
script name: forms
Created on 2019/12/31 17:23 by PyCharm
@author: fujianjian
"""

from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, BooleanField, SubmitField
from wtforms.validators import Length, Email, Regexp, DataRequired, EqualTo


class LoginForm(FlaskForm):
    """
    登入表格
    """
    email = StringField('邮箱', validators=[DataRequired(), Length(1, 64), Email()])
    password = PasswordField('密码', validators=[DataRequired(), Length(1, 64)])
    remember_me = BooleanField('记住我')
    submit = SubmitField('登入')


class RegisterForm(FlaskForm):
    email = StringField('邮箱', validators=[Length(1, 64), Email()])
    username = StringField('用户名',
                           validators=[Length(1, 64), DataRequired(), Regexp('^[A-Za-z0-9_.]*$', 0, '用户名必须使用字母数组组成')])
    password = PasswordField('密码', validators=[Length(1, 64), DataRequired()])
    comfirm_password = PasswordField('确认密码', validators=[Length(1, 64), DataRequired(),
                                                         EqualTo('password', message='两次密码必须一致')])

    submit = SubmitField('注册')

    def validate_email(self, field):
        pass

    def validate_username(self, field):
        pass
